package com.uniandes.edu.co.interfaz.ciclo;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JLabel;
import javax.swing.AbstractButton;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.WindowConstants;
import javax.swing.border.BevelBorder;
import javax.swing.SwingUtilities;
import javax.swing.event.TableModelEvent;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

import com.uniandes.edu.co.controlador.ControladorCiclo;
import com.uniandes.edu.co.dto.Ciclo;
import com.uniandes.edu.co.dto.Tsp;
import com.uniandes.edu.co.excepciones.ExcepcionExiste;
import com.uniandes.edu.co.excepciones.ExcepcionParseInt;
import com.uniandes.edu.co.excepciones.ExcepcionVacio;



/**
 * This code was edited or generated using CloudGarden's Jigloo
 * SWT/Swing GUI Builder, which is free for non-commercial
 * use. If Jigloo is being used commercially (ie, by a corporation,
 * company or business for any purpose whatever) then you
 * should purchase a license for each developer using Jigloo.
 * Please visit www.cloudgarden.com for details.
 * Use of Jigloo implies acceptance of these licensing terms.
 * A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
 * THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
 * LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
@SuppressWarnings("serial")
public class InterfazModificarCiclo extends javax.swing.JFrame {
    private JScrollPane jScrollPane1;
    private JLabel jLabel5;
    private JButton jButton1;
    private JTextArea jTextArea2;
    private JScrollPane jScrollPane4;
    private JTextArea jTextArea1;
    private JScrollPane jScrollPane3;
    private JLabel jLabel4;
    private JScrollPane jScrollPane2;
    private JLabel jLabel6;
    private JButton jButton5;
    private JLabel jLabel3;
    private JTextField jTextField1;
    private JLabel jLabel2;
    private JLabel jLabel1;

    /**
     * Auto-generated main method to display this JFrame
     */
    public static void main(String[] args, final String idCiclo) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                InterfazModificarCiclo inst = new InterfazModificarCiclo(idCiclo);
                inst.setLocationRelativeTo(null);
                inst.setVisible(true);
            }
        });
    }
    public InterfazModificarCiclo( String idCiclo) {
        super();
        initGUI(idCiclo);
    }


    private void initGUI( String idCiclo) {
        try {
            setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
            getContentPane().setLayout(null);
           
            Ciclo ciclo= Tsp.getSingleton().obtenerCiclo(idCiclo);
           
            {
                jScrollPane1 = new JScrollPane();
                getContentPane().add(jScrollPane1);
                final DefaultTableModel dm = new DefaultTableModel();
               
                dm.setDataVector(ControladorCiclo.getSingleton().tablaRequerimientos(ciclo.getRequerimientos()), ControladorCiclo.getSingleton().encabezadosRequerimientos());

                TableModel jTable1Model =dm;
                JTable jTable1 = new JTable(dm) {
                    public void tableChanged(TableModelEvent e) {
                        super.tableChanged(e);
                        repaint();
                    }
                };

                ButtonGroup group1 = new ButtonGroup();
                for (int i = 0; i < dm.getRowCount(); i++)
                {
                    group1.add( (AbstractButton) dm.getValueAt(i, 0));
                }
               
                jTable1.setModel(jTable1Model);
                jTable1.getColumn("Seleccionar").setCellRenderer(
                        new RadioButtonRenderer());
                jTable1.getColumn("Seleccionar").setCellEditor(
                        new RadioButtonEditor(new JCheckBox()));
                jScrollPane1.setBounds(40, 307, 386, 96);
                jScrollPane1.setViewportView(jTable1);
                jTable1.setBounds(161, 251, 231, 93);


            }
            {
                jLabel1 = new JLabel();
                getContentPane().add(jLabel1);
                jLabel1.setText("CICLO");
                jLabel1.setBounds(46, 12, 386, 26);
                jLabel1.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
                jLabel1.setFont(new java.awt.Font("Tahoma",1,14));
                jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
                jLabel1.setHorizontalTextPosition(SwingConstants.CENTER);
            }
            {
                jLabel2 = new JLabel();
                getContentPane().add(jLabel2);
                jLabel2.setText("Id Ciclo");
                jLabel2.setBounds(45, 51, 142, 20);
                jLabel2.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
            }
            {
                jLabel3 = new JLabel();
                getContentPane().add(jLabel3);
                jLabel3.setText("Estrategia");
                jLabel3.setBounds(45, 80, 142, 20);
                jLabel3.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
            }
           
            
            {
                jButton5 = new JButton();
                getContentPane().add(jButton5);
                jButton5.setText("Regresar");
                jButton5.setBounds(313, 586, 113, 21);
                jButton5.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                       dispose();
                       InterfazCiclo.main(null);
                    }
                });
            }
            {
            	jLabel5 = new JLabel();
            	getContentPane().add(jLabel5);
            	jLabel5.setText("Plan de desarrollo");
            	jLabel5.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
            	jLabel5.setBounds(44, 167, 142, 20);
            }
            {
            	jTextField1 = new JTextField();
            	getContentPane().add(jTextField1);
            	jTextField1.setBounds(205, 50, 226, 23);
            	jTextField1.setEditable(false);
            }
            {
            	jLabel6 = new JLabel();
            	getContentPane().add(jLabel6);
            	jLabel6.setText("Requerimientos");
            	jLabel6.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
            	jLabel6.setBounds(40, 270, 142, 20);
            }
            {
      
            	{
            		jScrollPane2 = new JScrollPane();
            		getContentPane().add(jScrollPane2);
            		jScrollPane2.setBounds(40, 463, 386, 96);
            		
            	{
            		jLabel4 = new JLabel();
            		getContentPane().add(jLabel4);
            		jLabel4.setText("Tareas");
            		jLabel4.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
            		jLabel4.setBounds(40, 425, 142, 20);
            	}

            }
            {
                jScrollPane1 = new JScrollPane();
                getContentPane().add(jScrollPane1);
                final DefaultTableModel dm = new DefaultTableModel();

                dm.setDataVector(ControladorCiclo.getSingleton().tablaTareas(ciclo.getTareas()), ControladorCiclo.getSingleton().encabezadosTarea());

                TableModel jTable1Model =dm;
                JTable jTable1 = new JTable(dm) {
                    public void tableChanged(TableModelEvent e) {
                        super.tableChanged(e);
                        repaint();
                    }
                };

                ButtonGroup group1 = new ButtonGroup();
                for (int i = 0; i < dm.getRowCount(); i++)
                {
                    group1.add( (AbstractButton) dm.getValueAt(i, 0));
                }
               
                jTable1.setModel(jTable1Model);
                jTable1.getColumn("Seleccionar").setCellRenderer(
                        new RadioButtonRenderer());
                jTable1.getColumn("Seleccionar").setCellEditor(
                        new RadioButtonEditor(new JCheckBox()));
                jScrollPane1.setBounds(40, 307, 386, 96);
                jTable1.setBounds(40, 393, 383, 93);
                jScrollPane2.setViewportView(jTable1);
        	}
            {
            	jScrollPane3 = new JScrollPane();
            	getContentPane().add(jScrollPane3);
            	jScrollPane3.setBounds(205, 80, 226, 76);
            	{
            		jTextArea1 = new JTextArea();
            		jScrollPane3.setViewportView(jTextArea1);
            	}
            }
            {
            	jScrollPane4 = new JScrollPane();
            	getContentPane().add(jScrollPane4);
            	jScrollPane4.setBounds(204, 167, 227, 91);
            	{
            		jTextArea2 = new JTextArea();
            		jScrollPane4.setViewportView(jTextArea2);
            	}
            }
            {
            	jButton1 = new JButton();
            	getContentPane().add(jButton1);
            	jButton1.setText("Modificar");
            	jButton1.setBounds(189, 585, 113, 23);
            	jButton1.addActionListener(new ActionListener() {
            		public void actionPerformed(ActionEvent evt) {
            			try {
							Tsp.getSingleton().modificarCiclo(jTextField1.getText(), jTextArea1.getText(), jTextArea2.getText());
							JOptionPane.showMessageDialog(null, "Se ha modificado correctamente un ciclo");
							dispose();
							InterfazCiclo.main(null);
            			} catch (ExcepcionExiste e) {
							JOptionPane.showMessageDialog(null, e.getMessage());
						} catch (ExcepcionVacio e) {
							JOptionPane.showMessageDialog(null, e.getMessage());
						}catch (ExcepcionParseInt e) {
							JOptionPane.showMessageDialog(null, e.getMessage());
						}
            		}
            	});
            }
            jTextField1.setText(String.valueOf(ciclo.getIdCiclo()));
            jTextArea1.setText(ciclo.getEstrategia());
            jTextArea2.setText(ciclo.getPlanDesarrollo());
            }

            pack();
            this.setSize(477, 673);
           
        } catch (Exception e) {
            //add your error handling code here
            e.printStackTrace();
        }
    }
    


}
